{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4.使用 lightGBM 预测音乐推荐结果     模型测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 首先 import 必要的模块\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import pickle as pk\n",
    "import seaborn as sns\n",
    "import copy\n",
    "import matplotlib.pyplot as plt\n",
    "import scipy.io as sio\n",
    "import scipy.sparse as ss\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_path = '../Data/'  # 文件路径\n",
    "model_path = '../model/' # 模型路径"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 读取数据 & 数据探索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 载入测试数据\n",
    "# with open(model_path + 'data_all_test_v4.pkl','rb') as fr:\n",
    "#     test_X = pk.load(fr)\n",
    "# fr.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 载入测试数据 id\n",
    "with open(model_path + 'id_list_test.pkl','rb') as fr:\n",
    "    test_id = pk.load(fr)\n",
    "fr.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "76126     0\n",
       "790668    1\n",
       "52111     2\n",
       "159296    3\n",
       "160750    4\n",
       "Name: id, dtype: int64"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_id.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "# test_X['language'] = test_X.language.apply(lambda language_item : 'language_'+str(language_item))\n",
    "# test_X['artist_name'] = test_X['artist_name'].cat.add_categories(['artist_name_NaN']);\n",
    "# test_X['artist_name'] = test_X.artist_name.fillna('artist_name_NaN')\n",
    "# test_X['lyricist'] = test_X['lyricist'].cat.add_categories(['lyricist_NaN']);\n",
    "# test_X['lyricist'] = test_X.lyricist.fillna('lyricist_NaN')\n",
    "# test_X['composer'] = test_X['composer'].cat.add_categories(['composer_NaN']);\n",
    "# test_X['composer'] = test_X.composer.fillna('composer_NaN')\n",
    "# test_X['name'] = test_X['name'].cat.add_categories(['name_NaN']);\n",
    "# test_X['name'] = test_X.name.fillna('name_NaN')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 保存测试数据所有的类别特征\n",
    "# with open(model_path+'data_all_test_v5.pkl','wb') as fw:\n",
    "#     pk.dump(test_X, fw)\n",
    "# fw.close()\n",
    "\n",
    "# # 测试数据执行到这里先停止，到2_1 训练 LabelEncode"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 保存测试数据所有的类别特征\n",
    "with open(model_path+'data_all_test_v5.pkl','rb') as fr:\n",
    "    test_X = pk.load(fr)\n",
    "fr.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source_system_tab</th>\n",
       "      <th>source_screen_name</th>\n",
       "      <th>source_type</th>\n",
       "      <th>city</th>\n",
       "      <th>bd</th>\n",
       "      <th>gender</th>\n",
       "      <th>registered_via</th>\n",
       "      <th>song_length</th>\n",
       "      <th>language</th>\n",
       "      <th>reg_interval_days</th>\n",
       "      <th>...</th>\n",
       "      <th>genre_id_157</th>\n",
       "      <th>genre_id_158</th>\n",
       "      <th>genre_id_159</th>\n",
       "      <th>genre_id_160</th>\n",
       "      <th>genre_id_161</th>\n",
       "      <th>genre_id_162</th>\n",
       "      <th>genre_id_166</th>\n",
       "      <th>genre_id_164</th>\n",
       "      <th>genre_id_163</th>\n",
       "      <th>genre_id_165</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>language_3.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>my library</td>\n",
       "      <td>Local playlist more</td>\n",
       "      <td>local-library</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>language_3.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>discover</td>\n",
       "      <td>screen_name_NaN</td>\n",
       "      <td>song-based-playlist</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>gender_NaN</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>language_17.0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>language_52.0</td>\n",
       "      <td>10</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>radio</td>\n",
       "      <td>Radio</td>\n",
       "      <td>radio</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>language_-1.0</td>\n",
       "      <td>10</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 181 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       source_system_tab   source_screen_name          source_type city bd  \\\n",
       "76126         my library  Local playlist more        local-library    1  1   \n",
       "790668        my library  Local playlist more        local-library    1  1   \n",
       "52111           discover      screen_name_NaN  song-based-playlist    1  1   \n",
       "159296             radio                Radio                radio    3  3   \n",
       "160750             radio                Radio                radio    3  3   \n",
       "\n",
       "            gender registered_via song_length       language  \\\n",
       "76126   gender_NaN              7           1   language_3.0   \n",
       "790668  gender_NaN              7           2   language_3.0   \n",
       "52111   gender_NaN              4           2  language_17.0   \n",
       "159296        male              9           1  language_52.0   \n",
       "160750        male              9           1  language_-1.0   \n",
       "\n",
       "       reg_interval_days  ... genre_id_157 genre_id_158 genre_id_159  \\\n",
       "76126                  3  ...            0            0            0   \n",
       "790668                 3  ...            0            0            0   \n",
       "52111                  0  ...            0            0            0   \n",
       "159296                10  ...            0            0            0   \n",
       "160750                10  ...            0            0            0   \n",
       "\n",
       "       genre_id_160  genre_id_161  genre_id_162  genre_id_166  genre_id_164  \\\n",
       "76126             0             0             0             0             0   \n",
       "790668            0             0             0             0             0   \n",
       "52111             0             0             0             0             0   \n",
       "159296            0             0             0             0             0   \n",
       "160750            0             0             0             0             0   \n",
       "\n",
       "        genre_id_163  genre_id_165  \n",
       "76126              0             0  \n",
       "790668             0             0  \n",
       "52111              0             0  \n",
       "159296             0             0  \n",
       "160750             0             0  \n",
       "\n",
       "[5 rows x 181 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_X.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(test_X['name'].append(test_X['composer']))   # 拼接两个 series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "source_system_tab\n",
      "\n",
      "source_screen_name\n",
      "\n",
      "source_type\n",
      "\n",
      "city\n",
      "\n",
      "bd\n",
      "\n",
      "gender\n",
      "\n",
      "registered_via\n",
      "\n",
      "song_length\n",
      "\n",
      "language\n",
      "\n",
      "reg_interval_days\n",
      "\n",
      "artist_name\n",
      "\n",
      "composer\n",
      "\n",
      "genre_ids\n",
      "\n",
      "lyricist\n",
      "\n",
      "name\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 所有的类别型特征都进行标签编码\n",
    "for column in ['source_system_tab', 'source_screen_name', 'source_type', 'city', 'bd',\n",
    "       'gender', 'registered_via', 'song_length', 'language',\n",
    "       'reg_interval_days', 'artist_name', 'composer', 'genre_ids', 'lyricist',\n",
    "       'name']:\n",
    "    print(column+'\\n')\n",
    "    if column not in ['genre_ids']:\n",
    "        # 测试数据要使用训练数据时生成的 LabelEncoder 对象\n",
    "        with open(model_path+'LE'+column+'.pkl','rb') as fr:\n",
    "            le = pk.load(fr)\n",
    "        fr.close()\n",
    "        test_X[column] = le.transform(test_X[column])\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source_system_tab</th>\n",
       "      <th>source_screen_name</th>\n",
       "      <th>source_type</th>\n",
       "      <th>city</th>\n",
       "      <th>bd</th>\n",
       "      <th>gender</th>\n",
       "      <th>registered_via</th>\n",
       "      <th>song_length</th>\n",
       "      <th>language</th>\n",
       "      <th>reg_interval_days</th>\n",
       "      <th>...</th>\n",
       "      <th>genre_id_157</th>\n",
       "      <th>genre_id_158</th>\n",
       "      <th>genre_id_159</th>\n",
       "      <th>genre_id_160</th>\n",
       "      <th>genre_id_161</th>\n",
       "      <th>genre_id_162</th>\n",
       "      <th>genre_id_166</th>\n",
       "      <th>genre_id_164</th>\n",
       "      <th>genre_id_163</th>\n",
       "      <th>genre_id_165</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>0</td>\n",
       "      <td>22</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>5</td>\n",
       "      <td>16</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>5</td>\n",
       "      <td>16</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 181 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        source_system_tab  source_screen_name  source_type  city  bd  gender  \\\n",
       "76126                   3                   8            3     0   0       1   \n",
       "790668                  3                   8            3     0   0       1   \n",
       "52111                   0                  22            9     0   0       1   \n",
       "159296                  5                  16            7     1   2       2   \n",
       "160750                  5                  16            7     1   2       2   \n",
       "\n",
       "        registered_via  song_length  language  reg_interval_days  ...  \\\n",
       "76126                2            0         4                  3  ...   \n",
       "790668               2            1         4                  3  ...   \n",
       "52111                1            1         2                  0  ...   \n",
       "159296               3            0         8                 10  ...   \n",
       "160750               3            0         0                 10  ...   \n",
       "\n",
       "        genre_id_157  genre_id_158  genre_id_159  genre_id_160  genre_id_161  \\\n",
       "76126              0             0             0             0             0   \n",
       "790668             0             0             0             0             0   \n",
       "52111              0             0             0             0             0   \n",
       "159296             0             0             0             0             0   \n",
       "160750             0             0             0             0             0   \n",
       "\n",
       "        genre_id_162  genre_id_166  genre_id_164  genre_id_163  genre_id_165  \n",
       "76126              0             0             0             0             0  \n",
       "790668             0             0             0             0             0  \n",
       "52111              0             0             0             0             0  \n",
       "159296             0             0             0             0             0  \n",
       "160750             0             0             0             0             0  \n",
       "\n",
       "[5 rows x 181 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_X.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3    1019492\n",
       "0     871068\n",
       "6     277615\n",
       "5     212765\n",
       "2      98628\n",
       "1      66023\n",
       "8       8442\n",
       "4       2124\n",
       "7        633\n",
       "Name: source_system_tab, dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_X.source_system_tab.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2556790, 181)"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_X.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 2556790 entries, 76126 to 86415\n",
      "Columns: 181 entries, source_system_tab to genre_id_165\n",
      "dtypes: int64(14), uint8(167)\n",
      "memory usage: 699.8 MB\n"
     ]
    }
   ],
   "source": [
    "test_X.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(model_path + 'data_all_test_lgbm_v1.pkl','wb') as fw:\n",
    "    pk.dump(test_X,fw)\n",
    "fw.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用训练好的模型对结果进行预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [],
   "source": [
    "#load训练好的模型\n",
    "with open(model_path + 'lg_v2_2_1.pkl','rb') as fr:\n",
    "    lg = pk.load(fr)\n",
    "fr.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #load训练好的模型\n",
    "# with open(model_path + 'lg_v2_2_2.pkl','rb') as fr:\n",
    "#     lg_v2_2_2 = pk.load(fr)\n",
    "# fr.close()\n",
    "y_test_pred_lg_v2_2_2 = lg_v2_2_2.predict(test_X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #load训练好的模型\n",
    "# with open(model_path + 'lg_v2_2_3.pkl','rb') as fr:\n",
    "#     lg_v2_2_3 = pk.load(fr)\n",
    "# fr.close()\n",
    "y_test_pred_lg_v2_2_3 = lg_v2_2_3.predict(test_X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [],
   "source": [
    "# with open(model_path + 'lg_v4.pkl','rb') as fr:\n",
    "#     lg_v2_2_5 = pk.load(fr)\n",
    "# fr.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "#输出每类的概率\n",
    "y_test_pred = lg.predict(test_X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "# y_test_pred[62881:62981,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.62148486, 0.63598255, 0.26743884, ..., 0.41534637, 0.34568656,\n",
       "       0.42524073])"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_test_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2556790,)"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_test_pred.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.008050047331590576\n",
      "-0.007475744908433304\n",
      "-0.06218624738018671\n",
      "-0.022076986145911956\n",
      "-0.006248001372837341\n",
      "-0.033324935701426715\n",
      "-0.017152861708886608\n",
      "-0.046915478537381046\n",
      "-0.014513857902030636\n",
      "-0.005312031838724175\n",
      "-0.00469514964838364\n",
      "-0.028966935508828607\n",
      "-0.01237449044457564\n",
      "-0.01530361053487209\n",
      "-0.018965153835935746\n",
      "-0.05035533790101531\n",
      "-0.009099505747696015\n",
      "-0.012961501711150361\n",
      "-0.011958077671829673\n",
      "-0.007916934138024433\n",
      "-0.022864755789484582\n",
      "-0.007081380419867342\n",
      "-0.00739864783431699\n",
      "-0.00428412685107747\n",
      "-0.0037509697687094497\n",
      "-0.07715264282909669\n",
      "-0.003049446410799633\n",
      "-0.014366502805587647\n",
      "-0.01898862257552882\n",
      "-0.00428412685107747\n",
      "-0.010786944023029777\n",
      "-0.009355362846226577\n",
      "-0.009510943111970307\n",
      "-0.018936865599496026\n",
      "-0.02284613271699713\n",
      "-0.012703073191213563\n",
      "-0.020633051004520318\n",
      "-0.017880021069599145\n",
      "-0.028505626654339682\n",
      "-0.017684965991921226\n",
      "-0.0020876308725278564\n",
      "-0.03868598840109971\n",
      "-0.013485263126416527\n",
      "-0.017992333125401334\n",
      "-0.019054168936904297\n",
      "-0.03857365038504113\n",
      "-0.0002932540676854\n",
      "-0.11981681816280605\n",
      "-0.00398246623946505\n",
      "-0.012703073191213563\n",
      "-0.0143597271554649\n",
      "-0.03908732014052481\n",
      "-0.019184204184279362\n",
      "-0.025366910154261138\n",
      "-0.0038790120108566084\n",
      "-0.0036792802045650832\n",
      "-0.016664031777443963\n",
      "-0.003578349654239733\n",
      "-0.024743491916280794\n",
      "-0.041731718989213226\n",
      "-0.0010424769026198253\n",
      "-0.006204312344807746\n",
      "-0.05246121839105702\n",
      "-0.009884023126950024\n",
      "-0.012703073191213563\n",
      "-0.0035054911546097433\n",
      "-0.012076727132295429\n",
      "-0.008198535541273212\n",
      "-0.0011816964165695541\n",
      "-0.014911692600846339\n",
      "-0.012396678436135055\n",
      "-0.03908732014052481\n",
      "-0.033140184981169656\n",
      "-0.009921354389942834\n",
      "-0.022312194716489764\n",
      "-0.001393735385917416\n",
      "-0.012396678436135055\n",
      "-0.005707028388000663\n",
      "-0.005418705571427252\n",
      "-0.002524583828000652\n",
      "-0.0429230284429193\n",
      "-0.015502646215588545\n",
      "-0.05415911046031416\n",
      "-0.03123991333748536\n",
      "-0.022675490319909588\n",
      "-0.0429230284429193\n",
      "-0.020721953616515056\n",
      "-0.004918838028975687\n",
      "-0.021735742739250035\n",
      "-0.014306176367501195\n",
      "-0.004949789794006179\n",
      "-0.004233233592913417\n",
      "-0.0005390146139568058\n",
      "-0.025242494651749808\n",
      "-0.016145320979974422\n",
      "-0.007919325771656273\n",
      "-0.012703073191213563\n",
      "-0.0012083401412445389\n",
      "-0.016298217253030493\n",
      "-0.05928194386168232\n",
      "-0.008794194434432046\n",
      "-0.0017260633597136036\n",
      "-0.012703073191213563\n",
      "-0.005988781626899109\n",
      "-0.007491953188742536\n",
      "-0.005043405386007651\n",
      "-0.028565830834042003\n",
      "-0.0009467372493288765\n",
      "-0.06386932801765008\n",
      "-0.00641183882385713\n",
      "-0.05586542327735361\n",
      "-0.012703073191213563\n",
      "-0.015583330907384535\n",
      "-0.007895677152372669\n",
      "-0.007275589364752753\n",
      "-0.007478277018019399\n",
      "-0.014115903576532127\n",
      "-0.0005368607715214932\n",
      "-0.01388652770582467\n",
      "-0.04049582259902624\n",
      "-0.005996671033109708\n",
      "-0.026489271331979425\n",
      "-0.021735742739250035\n",
      "-0.015235483427956546\n",
      "-0.046011578993736514\n",
      "-0.004161928380893787\n",
      "-0.01682755685119081\n",
      "-0.012703073191213563\n",
      "-0.05306717817665554\n",
      "-0.0070715002370668745\n",
      "-0.017224973327406325\n",
      "-0.024961405604225582\n",
      "-0.07603728703526388\n",
      "-0.0017939545978022085\n",
      "-0.010187789688976509\n",
      "-0.009369441900364355\n",
      "-0.012703073191213563\n",
      "-6.749667030131213e-05\n",
      "-0.05901868755893045\n",
      "-0.02540686530948332\n",
      "-0.05794741632085686\n",
      "-0.012523026116784042\n",
      "-0.01333638848693481\n",
      "-0.007540671697294087\n",
      "-0.012618580587838038\n",
      "-0.023494218080705863\n",
      "-0.009182934224836696\n",
      "-0.02522727061314435\n",
      "-0.007965383157193598\n",
      "-0.04300809995374242\n",
      "-0.00957034209369604\n",
      "-0.0447831856387321\n",
      "-0.05794741632085686\n",
      "-0.054148775899522966\n",
      "-0.002094008714190144\n",
      "-0.010969439671664142\n",
      "-0.024348693938786383\n",
      "-0.006371659804104294\n",
      "-0.006359541382272822\n",
      "-0.0008897559927043122\n",
      "-0.003889360880135613\n",
      "-0.012396678436135055\n",
      "-0.003959794000279545\n",
      "-0.000876306395014528\n",
      "-0.04914383475501353\n",
      "-0.09958231416281334\n",
      "-0.024086615937762908\n",
      "-0.006647216258031273\n",
      "-0.018690659039654518\n",
      "-0.0028135928595517303\n",
      "-0.12440557262226977\n",
      "-0.005942111771292404\n",
      "-0.0030318837853824795\n",
      "-0.1231419282095914\n",
      "-0.020100209464528146\n",
      "-0.016321398886477757\n",
      "-0.002900433979117466\n",
      "-0.0018926885365221169\n",
      "-0.027828357672440577\n",
      "-0.016085530474844793\n",
      "-0.024071014011623187\n",
      "-0.0489115974883859\n",
      "-0.031401474207560426\n",
      "-0.0011863559359419499\n",
      "-0.0049782173711646486\n",
      "-0.010819189610676946\n",
      "-0.010697765923062198\n",
      "-0.013589296619822578\n",
      "-0.011411380027927798\n",
      "-0.021170948938194014\n",
      "-0.0012048441046069167\n",
      "-0.012703073191213563\n",
      "-0.046011578993736514\n",
      "-0.009975772786933911\n",
      "-0.0387979684254716\n",
      "-0.026360052883083754\n",
      "-0.012703073191213563\n",
      "-0.0447831856387321\n",
      "-0.017615433629840405\n",
      "-0.03791157552842\n",
      "-0.04790079626201972\n",
      "-0.004033585883242469\n",
      "-0.018449079379354784\n",
      "-0.03449815292051544\n",
      "-0.025944656203197754\n",
      "-0.03880110825835114\n",
      "-0.06449432158627505\n",
      "-0.012703073191213563\n",
      "-0.024984543299176615\n",
      "-0.05680911134734067\n",
      "-0.10669241820813673\n",
      "-0.00931985860527783\n",
      "-0.005760639240854727\n",
      "-0.0798817677606592\n",
      "-0.08540808314660296\n",
      "-0.0015068904881681898\n",
      "-0.018408634855609753\n",
      "-0.017594803857784194\n",
      "-0.016506599424528718\n",
      "-0.020149380800490262\n",
      "-0.06648129855332681\n",
      "-0.07309144539087045\n",
      "-0.043049501042018434\n",
      "-0.05738355637329761\n",
      "-0.0699486949212426\n",
      "-0.0458004008358555\n",
      "-0.018449079379354784\n",
      "-0.013014061100724448\n",
      "-0.024871267377775355\n",
      "-0.01043923832030882\n",
      "-0.015379835069852747\n",
      "-0.009312078244978208\n",
      "-0.06656201005550343\n",
      "-0.00958722676405365\n",
      "-0.08728934176391044\n",
      "-0.04708132784086002\n",
      "-0.008921421159240233\n",
      "-0.0041107734218325\n",
      "-0.024357025392547336\n",
      "-0.006973463359985578\n",
      "-0.006973463359985578\n",
      "-0.012396678436135055\n",
      "-0.006239538307127449\n",
      "-0.009445258092164645\n",
      "-0.0447831856387321\n",
      "-0.1231419282095914\n",
      "-0.0030318837853824795\n",
      "-0.003157963056946802\n",
      "-0.022068380357890938\n",
      "-0.012703073191213563\n",
      "-0.046011578993736514\n",
      "-0.0036381341921894786\n",
      "-0.05226123513135929\n",
      "-0.029211477383916423\n",
      "-0.005740180719746408\n",
      "-0.0447831856387321\n",
      "-0.016386079879923725\n",
      "-0.008168500223918329\n",
      "-0.007895677152372669\n",
      "-0.028785285165437595\n",
      "-0.054454655127310396\n",
      "-0.06769576476171266\n",
      "-0.033366422753070835\n",
      "-0.010108761667225198\n",
      "-0.05496088544261909\n",
      "-0.012703073191213563\n",
      "-0.013128453324233265\n",
      "-0.06112528443164396\n",
      "-0.06904805802905242\n",
      "-0.026631154211058546\n",
      "-0.00863647282526618\n",
      "-0.07036854305413465\n",
      "-0.11667194507994808\n",
      "-0.019528237682233884\n",
      "-0.04982470036259152\n",
      "-0.005343169761055757\n",
      "-0.0072646092302936244\n",
      "-0.021829508199185856\n",
      "-0.015489708614591148\n",
      "-0.01586341073975686\n",
      "-0.022476785445682077\n",
      "-0.022433785892146087\n",
      "-0.02055656383353164\n",
      "-0.026752713846487\n",
      "-0.03371539100444181\n",
      "-0.013923046250304051\n",
      "-0.008209997936949374\n",
      "-0.012903706925091197\n",
      "-0.02730025023762046\n",
      "-0.0009437573581708976\n",
      "-0.01380291410085213\n",
      "-0.02421524920424257\n",
      "-0.009496141794008048\n",
      "-0.03930466163342738\n",
      "-0.02460018325560787\n",
      "-0.02345845172777214\n",
      "-0.03337096224891268\n",
      "-0.009271838349176617\n",
      "-0.04025470380416939\n",
      "-0.07562604271198436\n",
      "-0.03640027001096092\n",
      "-0.05067812490595779\n",
      "-0.04151283473493417\n",
      "-0.02170965126634611\n",
      "-0.009230074293020883\n",
      "-0.0442722761236543\n",
      "-0.0356003919098903\n",
      "-0.05374238327402044\n",
      "-0.02446100635280687\n",
      "-0.03937974208449509\n",
      "-0.045570011504161755\n",
      "-0.0020823528547737323\n",
      "-0.014900329233362281\n",
      "-0.016376427649020656\n",
      "-0.08993298097907111\n",
      "-0.00011460709243910621\n",
      "-0.002084149879722388\n",
      "-0.0017323148431780296\n",
      "-0.10131536112308873\n",
      "-0.01909734918863896\n",
      "-0.0005577710169163572\n",
      "-0.013007160108507328\n",
      "-0.031477868168952185\n",
      "-0.010805477793622276\n",
      "-0.0024454520849052485\n",
      "-0.017307169684328095\n",
      "-0.01397820711308724\n",
      "-0.008209997936949374\n",
      "-0.01734142485064876\n",
      "-0.017199301789840304\n",
      "-0.0007558648650670668\n",
      "-0.08538164098180186\n",
      "-0.00451826903522845\n",
      "-0.0031824105428486034\n",
      "-0.01891706390076595\n",
      "-0.024063292858480585\n",
      "-0.0005390146139568058\n",
      "-0.022475951172256054\n",
      "-0.010614009122671629\n",
      "-0.005120761326311066\n",
      "-0.006888969068049102\n",
      "-0.009637418820538398\n",
      "-0.01259629817511086\n",
      "-0.02177625213687474\n",
      "-0.006492723332798649\n",
      "-0.0078120529481960875\n",
      "-0.00533001719359378\n",
      "-0.009852447607693585\n",
      "-0.013594730405029594\n",
      "-0.007834108978955916\n",
      "-0.011591735075029804\n",
      "-0.12898103329777683\n",
      "-0.00797809838648386\n",
      "-0.005110556149876586\n",
      "-0.11733201833627503\n",
      "-0.0014638543609925166\n",
      "-0.015427393538502896\n",
      "-0.0019901573233412923\n",
      "-0.02381290031667156\n",
      "-0.0028115941202777857\n",
      "-0.039611398400552535\n",
      "-0.0007007985278676432\n",
      "-0.009017629063531273\n",
      "-0.004822439468413046\n",
      "-0.042366118053420505\n",
      "-0.01817433045072844\n",
      "-0.029513801755416826\n",
      "-0.009075261910601227\n",
      "-0.004149827426297752\n",
      "-0.003995000505928334\n",
      "-0.011112119170137583\n",
      "-0.01100169584932029\n",
      "-0.004745834029024108\n",
      "-0.02286055169177746\n",
      "-0.0031588400763189924\n",
      "-0.007926459809157831\n",
      "-0.037940006681624276\n",
      "-0.018515507687566466\n",
      "-0.027605752324113417\n",
      "-0.006104100639852783\n",
      "-0.009356003680536889\n",
      "-0.005857778339026087\n",
      "-0.00767304856986033\n",
      "-0.012632628299098921\n",
      "-0.01567184518386569\n",
      "-0.0056443907375716\n",
      "-0.012365291849486497\n",
      "-0.11934347856172951\n",
      "-0.027113921851712387\n",
      "-0.00981785794037426\n",
      "-0.008595421874094431\n",
      "-0.016865259008176287\n",
      "-0.009597018083407344\n",
      "-0.007788005096116683\n",
      "-0.0072187649204645855\n",
      "-0.009128127637399766\n",
      "-0.012006950074953495\n",
      "-0.0058375562729691246\n",
      "-0.019276176985596433\n",
      "-0.005116656552814087\n",
      "-0.012703073191213563\n",
      "-0.010614009122671629\n",
      "-0.014872908622274928\n",
      "-0.03731802553005882\n",
      "-0.12043037714320878\n",
      "-0.00010553059276776211\n",
      "-0.012787569889106573\n",
      "-0.00957227930794124\n",
      "-0.018519561039063968\n",
      "-0.007310441372455438\n",
      "-0.03723086236890658\n",
      "-0.0033701344489749908\n",
      "-0.006698606559451485\n",
      "-0.019408566444707703\n",
      "-0.015244547174789938\n",
      "-0.012811630389398065\n",
      "-0.012309533656852953\n",
      "-0.0009710547430912038\n",
      "-0.010420016510946923\n",
      "-0.019229894927318882\n",
      "-0.014069883565078094\n",
      "-0.03765409259368988\n",
      "-0.017102879710131018\n",
      "-0.010228076112745793\n",
      "-0.010139285571790063\n",
      "-0.01782468463732803\n",
      "-0.013458875774757429\n",
      "-0.004293228498253569\n",
      "-0.02911120378622116\n",
      "-0.0055154840104352345\n",
      "-0.03500895759186296\n",
      "-0.02031431696493072\n",
      "-0.012703073191213563\n",
      "-0.018496128202558346\n",
      "-0.04209361193907797\n",
      "-0.014758713592244461\n",
      "-0.011000924340091138\n",
      "-0.006071357907082805\n",
      "-0.005108079923960778\n",
      "-0.012103365446859821\n",
      "-0.022220015964626888\n",
      "-0.022220015964626888\n",
      "-0.022220015964626888\n",
      "-0.022220015964626888\n",
      "-0.022220015964626888\n",
      "-0.011660047715764201\n",
      "-0.010932583441222051\n",
      "-0.0018847776860374905\n",
      "-0.0016735243073527583\n",
      "-0.05634488572159081\n",
      "-0.05800600383406538\n",
      "-0.0036883043374985355\n",
      "-0.003066303807783928\n",
      "-0.07144271425534617\n",
      "-0.022848365561441836\n",
      "-0.02037249775557065\n",
      "-0.022682397588549855\n",
      "-0.013815393571430147\n",
      "-0.018653100520584567\n",
      "-0.014119817950108016\n",
      "-0.015721110172183278\n",
      "-0.011966322202997742\n",
      "-0.04927024612495284\n",
      "-0.007333938282787222\n",
      "-0.03421254493534081\n",
      "-0.05819651785050014\n",
      "-0.022532717176855965\n",
      "-0.02478330703229543\n",
      "-0.03752410753852099\n",
      "-0.03195820503942541\n",
      "-0.025332415660958802\n",
      "-0.025510684579532938\n",
      "-0.022784636876966993\n",
      "-0.06581796739556378\n",
      "-0.01556094812635693\n",
      "-0.03610748370809067\n",
      "-0.04393936085506567\n",
      "-0.018997409389757372\n",
      "-0.03377659932158449\n",
      "-0.009660885852536416\n",
      "-0.02379191471823953\n",
      "-0.002656124852761159\n",
      "-0.01598963864351284\n",
      "-0.02559579759148926\n",
      "-0.02564122075416662\n",
      "-0.029402618321347263\n",
      "-0.02556548215311443\n",
      "-0.01916167255709172\n",
      "-0.01374025154248842\n",
      "-0.012631512426840068\n",
      "-0.04090466383425062\n",
      "-0.013059047031129188\n",
      "-0.032087773732475205\n",
      "-0.011467158365835341\n",
      "-0.0356855583607471\n",
      "-0.022784636876966993\n",
      "-0.014496775415393225\n",
      "-0.05938919128822434\n",
      "-0.044151712596892365\n",
      "-0.03420212442845826\n",
      "-0.0433121336610352\n",
      "-0.0228117356673327\n",
      "-0.03421254493534081\n",
      "-0.050310545870655685\n",
      "-0.016664442378960854\n",
      "-0.02556548215311443\n",
      "-0.023167945770679564\n",
      "-0.03375417996742345\n",
      "-0.032204210795012414\n",
      "-0.0350206062374517\n",
      "-0.02869101896842707\n",
      "-0.010836594485647064\n",
      "-0.028693477847124258\n",
      "-0.026577963012324273\n",
      "-0.032246636659853944\n",
      "-0.029520010824660093\n",
      "-0.024970668504045775\n",
      "-0.006711240363737314\n",
      "-0.03398526888263389\n",
      "-0.0333436997833261\n",
      "-0.04397463442255021\n",
      "-0.013059047031129188\n",
      "-0.04141095012888866\n",
      "-0.019770745044457867\n",
      "-0.03973737161800931\n",
      "-0.0067066620722114004\n",
      "-0.027651346409294616\n",
      "-0.013903485113575649\n",
      "-0.03172596696385914\n",
      "-0.017162474157327058\n",
      "-0.035377282083177086\n",
      "-0.028040903447689176\n",
      "-0.033028178913303244\n",
      "-0.037606240694519094\n",
      "-0.024007102446441348\n",
      "-0.0366560829096507\n",
      "-0.025332415660958802\n",
      "-0.03811316586256726\n",
      "-0.0015205404402947684\n",
      "-0.02038960713462516\n",
      "-0.03625803056872135\n",
      "-0.008512823355012399\n",
      "-0.005596428496103652\n",
      "-0.018465365669393666\n",
      "-0.07743785491031673\n",
      "-0.035347132297871287\n",
      "-0.022546406759897455\n",
      "-0.05778834822364612\n",
      "-0.03384150097298366\n",
      "-0.0422808133415757\n",
      "-0.01986745013238193\n",
      "-0.06638514312573995\n",
      "-0.03282785667309552\n",
      "-0.07967905338646848\n",
      "-0.026016363238142767\n",
      "-0.03696854753304733\n",
      "-0.025707076852375315\n",
      "-0.012631512426840068\n",
      "-0.03610416895005113\n",
      "-0.022444736964304088\n",
      "-0.0350206062374517\n",
      "-0.036181843300008266\n",
      "-0.007762988265175392\n",
      "-0.015583330907384535\n",
      "-0.00854062151465495\n",
      "-0.03577569347952746\n",
      "-0.15751331354679982\n",
      "-0.0006224323017562911\n",
      "-0.06779380962391639\n",
      "-0.05389685023583722\n",
      "-0.004368807112686886\n",
      "-0.00828573102805464\n",
      "-0.02616718807488008\n",
      "-0.010838419814551805\n",
      "-0.02915844066935188\n",
      "-0.02780834595048953\n",
      "-0.017347857725031342\n",
      "-0.03184714929440583\n",
      "-0.053287744390433565\n",
      "-0.05749833103506867\n",
      "-0.02820208781153954\n",
      "-0.024337186625385837\n",
      "-0.030763075580430073\n",
      "-0.035923906174099324\n",
      "-0.038512368520790964\n",
      "-0.03388958206188326\n",
      "-0.03628649751345112\n",
      "-0.03428009819927108\n",
      "-0.02556931081008094\n",
      "-0.02564122075416662\n",
      "-0.008310486887647952\n",
      "-0.034747699497042185\n",
      "-0.017681382291452108\n",
      "-0.033677004494783995\n",
      "-0.04050337743364492\n",
      "-0.008231463405774528\n",
      "-0.025762890550487017\n",
      "-0.017037104990199566\n",
      "-0.017748125668377836\n",
      "-0.02942551301178438\n",
      "-0.024811804865531903\n",
      "-0.01835010501525066\n",
      "-0.02233959015460222\n",
      "-0.02391838219803398\n",
      "-0.030726601585445237\n",
      "-0.1166335725685943\n",
      "-0.015209423474044375\n",
      "-0.012783037293127941\n",
      "-0.007899077428557609\n",
      "-0.03152190552100617\n",
      "-0.024659985711341172\n",
      "-0.06048391497847483\n",
      "-0.04755497401021683\n",
      "-0.037215504345468546\n",
      "-0.005864508908959417\n",
      "-0.04335018912260935\n",
      "-0.07744143548212835\n",
      "-0.18991319664524464\n",
      "-0.039894414879257836\n",
      "-0.015923350173094278\n",
      "-0.14398347301876882\n",
      "-0.031845005819908186\n",
      "-0.008310486887647952\n",
      "-0.041188199389656184\n",
      "-0.018105641862907317\n",
      "-0.050451773368308334\n",
      "-0.0074344299945294555\n",
      "-0.04028155322967165\n",
      "-0.02797343325208747\n",
      "-0.07871409683102626\n",
      "-0.01103951286642755\n",
      "-0.053487783440417845\n",
      "-0.01598963864351284\n",
      "-0.03893395891900772\n",
      "-0.029623024283955805\n",
      "-0.007491953188742536\n",
      "-0.009342133959256782\n",
      "-0.06640936426129343\n",
      "-0.011531253952534891\n",
      "-0.037718022052233596\n",
      "-0.02644003788167196\n",
      "-0.02200006646870357\n",
      "-0.0010772144950958562\n",
      "-0.005556093462404783\n",
      "-0.014382420421412904\n",
      "-0.05423716645933586\n",
      "-0.016847108582594045\n",
      "-0.03223368910677914\n",
      "-0.04017869424550289\n",
      "-0.0313670861287529\n",
      "-0.03223368910677914\n",
      "-0.08838669208317201\n",
      "-0.038968596358410136\n",
      "-0.028177521837899965\n",
      "-0.03786246083782177\n",
      "-0.04139795066636337\n",
      "-0.026928593369714236\n",
      "-0.012703073191213563\n",
      "-0.012705502568917032\n",
      "-0.012703073191213563\n",
      "-0.011958077671829673\n",
      "-0.0017617901884531975\n",
      "-0.01552574066985865\n",
      "-0.008232553165899574\n",
      "-0.051674700657174555\n",
      "-0.016895268580146394\n",
      "-0.020176513883838957\n",
      "-0.0034808598842565206\n",
      "-0.06894425891798642\n",
      "-0.012300859127935439\n",
      "-0.06252878664234013\n",
      "-0.054148775899522966\n",
      "-0.017514435276690377\n",
      "-0.009361275899932624\n",
      "-0.011958077671829673\n",
      "-0.012949652032555712\n",
      "-0.007608618104270029\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.059835690540274954\n",
      "-0.002780972633066342\n",
      "-0.01820001445505542\n",
      "-0.021439663504417367\n",
      "-0.004180825690807675\n",
      "-0.018879899647256965\n",
      "-0.00583847351769789\n",
      "-0.005265628120841741\n",
      "-0.013506954844085534\n",
      "-0.009208122680176628\n",
      "-0.030826393010102548\n",
      "-0.0016858054415185943\n",
      "-0.027242616119570844\n",
      "-0.004782070918210986\n",
      "-0.008305562902272983\n",
      "-0.009852210446430969\n",
      "-0.007442394304641616\n",
      "-0.010638075996036457\n",
      "-0.11162653381562855\n",
      "-0.003512981220459714\n",
      "-0.07028998253037068\n",
      "-0.1027488769824619\n",
      "-0.07731785104711601\n",
      "-0.0213324731385849\n",
      "-0.08658966786268607\n",
      "-0.003896221429122193\n",
      "-0.001995094559176138\n",
      "-0.012703073191213563\n",
      "-0.010696364444270736\n",
      "-0.04397450439408743\n",
      "-0.023338558175912676\n",
      "-0.011429117727592647\n",
      "-0.03341547244821936\n",
      "-0.042622723331785344\n",
      "-0.05909022453968948\n",
      "-0.05733073778903838\n",
      "-0.005169203209932314\n",
      "-0.03892998487695949\n",
      "-0.016373541432549005\n",
      "-0.012703073191213563\n",
      "-0.008605711459864166\n",
      "-0.017968486815632484\n",
      "-0.001880384503257533\n",
      "-0.01516330160246974\n",
      "-0.03703543074448989\n",
      "-0.0015205404402947684\n",
      "-0.033881595100522896\n",
      "-0.04950118037816447\n",
      "-0.048146962776060814\n",
      "-0.021362284126273216\n",
      "-0.028916867302113666\n",
      "-0.06471495009973846\n",
      "-0.002169310545053081\n",
      "-0.045001606604012936\n",
      "-0.03698311778482778\n",
      "-0.04990543769173875\n",
      "-0.04338851726830156\n",
      "-0.0619797600149458\n",
      "-0.0375479070920116\n",
      "-0.0320214798368129\n",
      "-0.03468210630987627\n",
      "-0.034208146757964665\n",
      "-0.00500271806656117\n",
      "-0.022784636876966993\n",
      "-0.03852100493447151\n",
      "-0.008412970339726586\n",
      "-0.015994951685800674\n",
      "-0.03269545927193709\n",
      "-0.024325879317461694\n",
      "-0.03893395891900772\n",
      "-0.014478412436299012\n",
      "-0.05611552986167967\n",
      "-0.01989223217390189\n",
      "-0.035936922100698765\n",
      "-0.03281190760470319\n",
      "-0.020253258801122522\n",
      "-0.034273196724962485\n",
      "-0.0023588813236390914\n",
      "-0.03398526888263389\n",
      "-0.01818154856159321\n",
      "-0.033351772786419744\n",
      "-0.06571419116739564\n",
      "-0.011256566874911153\n",
      "-0.04093336856343723\n",
      "-0.0239353296901808\n",
      "-0.028968886722763036\n",
      "-0.013795125947916426\n",
      "-0.00834406630545445\n",
      "-0.0381650509116653\n",
      "-0.03401221470474152\n",
      "-0.027933014564201997\n",
      "-0.01817015331930768\n",
      "-0.014382420421412904\n",
      "-0.03332497345591583\n",
      "-0.031060771070672392\n",
      "-0.02864558504829187\n",
      "-0.034910625094617315\n",
      "-0.03766078843729173\n",
      "-0.01327463642304286\n",
      "-0.03786246083782177\n",
      "-0.03763519500193712\n",
      "-0.02545647310367921\n",
      "-0.028693477847124258\n",
      "-0.01940222257244465\n",
      "-0.044151712596892365\n",
      "-0.028479087278017495\n",
      "-0.04393936085506567\n",
      "-0.025739325457436665\n",
      "-0.03855258309535276\n",
      "-0.035377282083177086\n",
      "-0.037133810409443406\n",
      "-0.011073839448015753\n",
      "-0.0432095064754897\n",
      "-0.04557577679150499\n",
      "-0.04557577679150499\n",
      "-0.03569692516333876\n",
      "-0.035967565187248696\n",
      "-0.043079768526289815\n",
      "-0.07466601272645326\n",
      "-0.014093641947309818\n",
      "-0.03162121647897119\n",
      "-0.024368334325795552\n",
      "-0.025932917457236547\n",
      "-0.07136951965413825\n",
      "-0.04311535690891526\n",
      "-0.01155940078797189\n",
      "-0.02915048938150425\n",
      "-0.012631512426840068\n",
      "-0.03732816552084185\n",
      "-0.04141095012888866\n",
      "-0.03764571752993727\n",
      "-0.026352560255320734\n",
      "-0.035254289772816916\n",
      "-0.02572350464405557\n",
      "-0.03732816552084185\n",
      "-0.019165609180494543\n",
      "-0.04057239889780561\n",
      "-0.035957298976703106\n",
      "-0.015100236828843353\n",
      "-0.024175707887101494\n",
      "-0.03282785667309552\n",
      "-0.007762988265175392\n",
      "-0.020790514559543942\n",
      "-0.01931931193757686\n",
      "-0.024266011468643572\n",
      "-0.03736744096007267\n",
      "-0.05464697488662398\n",
      "-0.04557577679150499\n",
      "-0.03375417996742345\n",
      "-0.04499027001382712\n",
      "-0.03325908645399817\n",
      "-0.012631512426840068\n",
      "-0.027654289153460746\n",
      "-0.018074795896416588\n",
      "-0.007899077428557609\n",
      "-0.028479087278017495\n",
      "-0.03162121647897119\n",
      "-0.04283595600577757\n",
      "-0.05078725964792929\n",
      "-0.03572689495714862\n",
      "-0.02790045747836491\n",
      "-0.07250068770980092\n",
      "-0.02556548215311443\n",
      "-0.060631516857950166\n",
      "-0.03457541864233899\n",
      "-0.04610199567734578\n",
      "-0.06991963961107761\n",
      "-0.030810601889620527\n",
      "-0.034254384573523776\n",
      "-0.007866590543960788\n",
      "-0.01598963864351284\n",
      "-0.027894354193226147\n",
      "-0.03842609930439518\n",
      "-0.011019805281795128\n",
      "-0.007199642532852925\n",
      "-0.03953312198616185\n",
      "-0.012703073191213563\n",
      "-0.027865151096272685\n",
      "-0.02332448709532636\n",
      "-0.004863832908748699\n",
      "-0.04478824547170367\n",
      "-0.049626360078641026\n",
      "-0.001053367410443299\n",
      "-0.02211210750203102\n",
      "-0.04376179028315747\n",
      "-0.04684117503656327\n",
      "-0.05851237993339084\n",
      "-0.0004471407396912042\n",
      "-0.04235086835118141\n",
      "-0.061563879190466894\n",
      "-0.06975522458259326\n",
      "-0.08100578207016465\n",
      "-0.06256772049572115\n",
      "-0.14621632743888208\n",
      "-0.054121967806590315\n",
      "-0.0816245258828188\n",
      "-0.002155644565293948\n",
      "-0.16828678186347532\n",
      "-0.04778803180181754\n",
      "-0.061526907413040025\n",
      "-0.06489639594583085\n",
      "-0.010455899374844164\n",
      "-0.03871036433475995\n",
      "-0.08295939643022474\n",
      "-0.04554786152332595\n",
      "-0.042597499481505416\n",
      "-0.08186373330499452\n",
      "-0.015845122022865178\n",
      "-0.07290375811729345\n",
      "-0.022848630708741744\n",
      "-0.07530834682291938\n",
      "-0.07705926342931996\n",
      "-0.02518866562165748\n",
      "-0.11231264220845981\n",
      "-0.07042380247437124\n",
      "-0.06517750763337803\n",
      "-0.01852787527688975\n",
      "-0.07501803503679996\n",
      "-0.06877657225100772\n",
      "-0.02159987688242356\n",
      "-0.014588302283899278\n",
      "-0.052770449385082255\n",
      "-0.06804940562540827\n",
      "-0.08342706389370681\n",
      "-0.07697687074685704\n",
      "-0.11363461745662057\n",
      "-0.06540601080856222\n",
      "-0.005261818195420897\n",
      "-0.04468196175946359\n",
      "-0.04384549807147008\n",
      "-0.0059005261516808785\n",
      "-0.0006600470731051407\n",
      "-0.047024222796373215\n",
      "-0.032625155116624255\n",
      "-0.04159067528146786\n",
      "-0.0375236097711722\n",
      "-0.03959573313637666\n",
      "-0.008261899685815994\n",
      "-0.0028699070194315147\n"
     ]
    }
   ],
   "source": [
    "for item in y_test_pred:\n",
    "    if item<0:\n",
    "        print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [],
   "source": [
    "predict_score = pd.DataFrame(test_id, index = test_id.index, columns=['id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "predict_score_bak = copy.deepcopy(predict_score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [],
   "source": [
    "# predict_score['target'] = y_test_pred[:,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>76126</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790668</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52111</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159296</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160750</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        id\n",
       "76126    0\n",
       "790668   1\n",
       "52111    2\n",
       "159296   3\n",
       "160750   4"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predict_score.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "def res_handler(x):\n",
    "    if x<0:\n",
    "        return 0\n",
    "    else:\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [],
   "source": [
    "# predict_score.target.apply(lambda x: print(x) if x>1 else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "predict_score['target'] = predict_score.target.apply(lambda x: res_handler(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [],
   "source": [
    "predict_score.to_csv(data_path+\"lg_v2_2_4.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [],
   "source": [
    "submission_v1 = pd.read_csv(data_path+'submission_v1.csv')\n",
    "submission_v2 = pd.read_csv(data_path+'submission_v2.csv')\n",
    "submission_v3 = pd.read_csv(data_path+'submission_v3.csv')\n",
    "submission_v4 = pd.read_csv(data_path+'lg_v2_2_4.csv')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.620794</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0.624357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>0.264992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>0.204126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0.247772</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id    target\n",
       "0   0  0.620794\n",
       "1   1  0.624357\n",
       "2   2  0.264992\n",
       "3   3  0.204126\n",
       "4   4  0.247772"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submission_v1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.625337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0.642530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>0.268172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>0.202228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0.254124</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id    target\n",
       "0   0  0.625337\n",
       "1   1  0.642530\n",
       "2   2  0.268172\n",
       "3   3  0.202228\n",
       "4   4  0.254124"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submission_v2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.631096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0.635337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>0.270978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>0.203851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0.256088</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id    target\n",
       "0   0  0.631096\n",
       "1   1  0.635337\n",
       "2   2  0.270978\n",
       "3   3  0.203851\n",
       "4   4  0.256088"
      ]
     },
     "execution_count": 185,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submission_v3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [],
   "source": [
    "for item in submission_v4_target:\n",
    "    if item<0:\n",
    "        print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [],
   "source": [
    "submission_v1['target'] = submission_v1.target.apply(lambda x: res_handler(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [],
   "source": [
    "submission_v2['target'] = submission_v2.target.apply(lambda x: res_handler(x))\n",
    "submission_v3['target'] = submission_v3.target.apply(lambda x: res_handler(x))\n",
    "submission_v4['target'] = submission_v4.target.apply(lambda x: res_handler(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [],
   "source": [
    "submission_v1.to_csv(data_path+\"submission_v1_positive.csv\", index=False)\n",
    "submission_v2.to_csv(data_path+\"submission_v2_positive.csv\", index=False)\n",
    "submission_v3.to_csv(data_path+\"submission_v3_positive.csv\", index=False)\n",
    "submission_v4.to_csv(data_path+\"submission_v4_positive.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
